$(function () {
    findDate();
    setUsername();
})

function findDate() {
    setInterval(function () {
            let dateTime = new Date();
            let year = dateTime.getFullYear();
            let month = dateTime.getMonth() + 1;
            let ri = dateTime.getDate();
            let day = null;
            if (dateTime.getDay() == 6) {
                day = "六";
            }
            if (dateTime.getDay() == 1) {
                day = "一";
            }
            if (dateTime.getDay() == 2) {
                day = "二";
            }
            if (dateTime.getDay() == 3) {
                day = "三";
            }
            if (dateTime.getDay() == 4) {
                day = "四";
            }
            if (dateTime.getDay() == 5) {
                day = "五";
            }
            if (dateTime.getDay() == 0) {
                day = "日";
            }
            var hours = dateTime.getHours();
            var minutes = dateTime.getMinutes();
            var seconds = dateTime.getSeconds();
            $("#localDate").html(year + "年" + month + "月" + ri + "日  " + hours + ":" + minutes + ":" + seconds + "  星期" + day);
        }
        , 1000)
}

function setUsername() {
    let result = myAjax('/se/security/getName', 'post', {});
    console.log(result);
    if (result==null){
        location.assign("/html/login.html")
    }
    if (result.code === 200) {
        $("#username").html(result.data);
        $("#username1").html(result.data);
    } else {
        location.assign("/html/login.html");
    }
}

//退出
function flushCookie() {
    let result = myAjax('/se/security/loginOut', 'post', {username:localStorage.getItem("user-name")});
    console.log(result);
    if (result.code===200){
        localStorage.setItem("token",null);
        location.assign("/html/login.html")
    }else if (result.code===401){
        alert(result.message);
    }else {
        alert("操作失败，请重新尝试")
    }
}

//赋值登录用户名
function setName() {
    sessionStorage.setItem("user-name", $("#username").text());
}

//修改密码
layui.use("layer");

function safety() {
    sessionStorage.setItem("user-name", $("#username").text());
    layer.open({
        type: 2,
        anim: 1,
        title: "安全设置",
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/safety.html', 'no'],
    })
}